# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=seabios
pkgver=1.13.0
pkgrel=0
pkgdesc="Open-source legacy BIOS implementation"
url="http://www.coreboot.org/SeaBIOS"
arch="x86 x86_64"
license="LGPL-3.0"
depends="$pkgname-bin=$pkgver-r$pkgrel seavgabios-bin=$pkgver-r$pkgrel"
makedepends="python3 iasl"
subpackages="$pkgname-bin:_seabios seavgabios-bin:_seavgabios"
source="$pkgname-$pkgver.tar.gz::https://github.com/coreboot/seabios/archive/rel-$pkgver.tar.gz
	0001-Workaround-for-a-win8.1-32-S4-resume-bug.patch
	0002-reserve-more-memory-on-fseg.patch

	config.coreboot
	config.csm
	config.seabios-128k
	config.seabios-256k
	config.vga.cirrus
	config.vga.isavga
	config.vga.qxl
	config.vga.stdvga
	config.vga.virtio
	config.vga.vmware
	"

_debug_level=1
_build_bios() {
	msg "building $3"
	make clean distclean
	cp "$1" .config
	echo "CONFIG_DEBUG_LEVEL=$_debug_level" >> .config
	make oldnoconfig
	make $4 PYTHON=python3
	cp out/"$2" binaries/"$3"
}

builddir="$srcdir/seabios-rel-$pkgver"

build() {
	mkdir binaries
	# seabois
	_build_bios "$srcdir"/config.csm Csm16.bin bios-csm.bin
	_build_bios "$srcdir"/config.coreboot bios.bin.elf bios-coreboot.bin
	_build_bios "$srcdir"/config.seabios-128k bios.bin bios.bin
	_build_bios "$srcdir"/config.seabios-256k bios.bin bios-256k.bin

	cp out/src/fw/*dsdt*.aml binaries/ || true

	for i in $source; do
		case $i in
		config.vga.*)
			_build_bios "$srcdir"/$i \
				vgabios.bin \
				vgabios-${i##*.}.bin \
				out/vgabios.bin
			;;
		esac
	done
}

package() {
	install -d "$pkgdir"/usr/share/seabios \
		"$pkgdir"/usr/share/seavgabios
	for i in binaries/*; do
		case ${i#*/} in
		bios*|*.aml) \
			install -m 0644 "$i" "$pkgdir"/usr/share/seabios/
			;;
		vga*)
			install -m 0644 "$i" "$pkgdir"/usr/share/seavgabios/
			;;
		esac
	done

	rm -f "$pkgdir"/.dummy
}

_seabios() {
	pkgdesc="Seabios for x86"
	depends=
	mkdir -p "$subpkgdir"/usr/share/
	mv "$pkgdir"/usr/share/seabios "$subpkgdir"/usr/share/
}

_seavgabios() {
	pkgdesc="Seavgabios for x86"
	depends=
	mkdir -p "$subpkgdir"/usr/share/
	mv "$pkgdir"/usr/share/seavgabios "$subpkgdir"/usr/share/
}

sha512sums="7f158badf7deecc2998eab2a08f3615dfe5a7c0a51323f7b4568a4d1280935bc32bb466c8226d87d2ca7e13f9f117ff0092befcc0699bc31c5018e84754e8393  seabios-1.13.0.tar.gz
cb8d74650e3b7136cfb62cd63e4bb5db16664dc6207cff034e17f0ae89b21b350994d375ba40a16037951a5c6d924cf517afa5eae1365b279478216e9a64a0c7  0001-Workaround-for-a-win8.1-32-S4-resume-bug.patch
56d0120bb84dc9dad863438d5651d220ca8d84e272427b1d5e7cd143b69d7ccde6d2dd9b950062fa81b5892fb4afb7ab3cfad3a461b696c600770b243622af42  0002-reserve-more-memory-on-fseg.patch
dc77f693e2426a8a9b084f22d607d9bf6dfd0776cb86373a55d6e02f154f546b6fd616bb981783e914be51eb843311652a90b111fb573e32b3a8207d66aea218  config.coreboot
a2238723fbbb96184bb52b018633701aeb929bfae43f50659258dee854acaf4f1bdf2c201c65fb46d2712372d11ab345eac1c41068f82d6dcbef91ef9d1d39cd  config.csm
6f6659dc7e6a14b4a9ab14ebb2c1769cc8ec5d520dc1ab5125437e213baa660b5cce1cad71c65fc8b4978c467e7a8d67ad1a42ad8accfb46e3bc654b0a1f64b9  config.seabios-128k
3d41739944da088edafb3ea298c0d3db59ed638b614c258209a30635caccf86a284f03492612694e3a56f40357743a0a36053e8ec11b7d93853b91ba9e5a502f  config.seabios-256k
e9ef2d6bec9419e69bc90adf1a4bb7c174284cd722e53903deea0411f88074cc247069116e03e124715072ec82f153cf6014168febba41369a2569983d3265b6  config.vga.cirrus
aada61232f4834c1e9bec921b1e1365ce5ecb4adf42c659f34cdf051efb56f0ec2e62f0ccf66bb25d9bb0b8601e2df49b712265f19185068d45353c3aacf1cd9  config.vga.isavga
9ebcb6702cf28685daf1821be26bab8ddc791ef2c118217c984c03c5fb77c8b9691c0fa6931367a63b8d97d67c973cd4b620fe9ca9c76da51a9b2ab3b4b5653b  config.vga.qxl
4a1b7fcc729d78dc8fd4e73d1cb6258ed9d49f8a91e6e00cc184e07c89a304f8d38ef5446d1c4ba5e8e929c82693d82c21526e42992ad6e1a008f39bb7c90448  config.vga.stdvga
4d627be11d79f0b8bd814a49e608826375aba6b59a0189dcba9afe24a181347b92e6ab18e0d9199e2f7a78f8fb02f03dad84c63fbbc2ffe9af76777ef28c5f8a  config.vga.virtio
2a82f75ca6dbf48546ffa5a756136dd7085855d9411c3b37a74cc53281027b4916cf628dba784bcad915682d94705b5f8116f7a1b7ec6a99d9b2fb3fffba01c0  config.vga.vmware"
